package com.errands.cn.services;

import com.errands.cn.entity.Orders;
import com.errands.cn.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    private OrdersMapper ordersMapper;

    @Transactional
    public boolean saveOrder(Orders order){
        try {
            ordersMapper.insert(order);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Transactional
    public boolean updateOrder(Orders order){
        try {
            ordersMapper.updateByPrimaryKeySelective(order);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Transactional
    public boolean deleteOrder(String oId){
        try {
            ordersMapper.deleteByPrimaryKey(oId);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public Orders findByOrderId(String oId){
      return  ordersMapper.selectByPrimaryKey(oId);
    }

    public List<Orders> getOrdersByentity(Orders orders){
        return ordersMapper.selectByPrimarySelectKey(orders);
    }

    public List<Orders> getOrdersByPrice(Integer minPrice,Integer maxPrice,String title,Integer goodsType,Integer oType){
        return ordersMapper.selectByPrice(minPrice,maxPrice,title,goodsType,oType);
    }
}
